package taskflow.config.bean;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import taskflow.constants.Parameter;

import java.util.function.Function;

/**
 * @author bailey
 */
public class TaskFlowPropertySetterBean implements EnvironmentAware{
	public static final String NAME_IN_CONTEXT = "taskFlowPropertySetter";
	public static final String NAME_OF_INIT_METHOD = "initProperties";
	
	private Environment environment;
	public void initProperties() {
		if (environment != null) {
			Function<String, String> valueGetter = environment::getProperty;
			Parameter.WORK_NO_EXISTS_IGNORABLE.refresh(valueGetter);
			Parameter.WORK_MAX_TASKS.refresh(valueGetter);
			Parameter.WORK_TRACEABLE.refresh(valueGetter);
			Parameter.TASK_ASYNC_TIMEOUT.refresh(valueGetter);
			Parameter.RELOAD_ENABLE.refresh(valueGetter);
			Parameter.LOG_PRINTABLE.refresh(valueGetter);
			Parameter.LOG_PRINT_DETAIL.refresh(valueGetter);
		}
	}

	@Override
	public void setEnvironment(Environment environment) {
		this.environment = environment;
	}

}
